package com.ribbon;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Ribbon来消费COMPUTE-SERVICE的add服务。通过直接RestTemplate来调用服务
 */
@Controller
public class ConsumerController {

    @Autowired
    ComputeService computeService;

    @RequestMapping(value = "/add", method = RequestMethod.GET,produces="application/json; charset=UTF-8")
    @ResponseBody
    public Map add() {
        Map<String,String> param = new ConcurrentHashMap<>();
        String result = computeService.addService();
        param.put("reusult",result);
        return param;
    }

}
